package com.example.testproject.adapter

import com.chad.library.adapter.base.BaseQuickAdapter
import com.chad.library.adapter.base.BaseViewHolder
import com.example.testproject.R
import com.example.testproject.activity.SelectParentBean
import kotlinx.android.synthetic.main.select_child.view.*

/**
 *
 * @ClassName: SelectChildAdapter
 * @Author: android 超级兵
 * @CreateDate: 10/19/21$ 3:38 PM$
 * TODO
 */
class SelectChildAdapter(
    data: List<SelectParentBean.SelectChildBean>,
    private val isSingleChoice: Boolean,
) :
    BaseQuickAdapter<SelectParentBean.SelectChildBean, BaseViewHolder>(R.layout.select_child,
        data) {

    override fun convert(helper: BaseViewHolder, item: SelectParentBean.SelectChildBean) {
        val checkBox = helper.itemView.checkbox
        checkBox.text = item.title

        checkBox.isChecked = item.isChildSelect

        checkBox.setOnClickListener {
            item.isChildSelect = !item.isChildSelect

            if (isSingleChoice) {
                click.onSingleChoiceClick(helper.adapterPosition)
                item.isChildSelect = !item.isChildSelect
            }
        }
    }

    interface SelectChildListener {
        fun onSingleChoiceClick(adapterPosition: Int)
    }

    lateinit var click: SelectChildListener
}